package com.fengmi.freemarker;

import freemarker.template.Configuration;
import freemarker.template.Template;

import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FreemarkerDemo {
    public static void main(String[] args) throws Exception{
        Configuration configuration = new Configuration(Configuration.getVersion());
        configuration.setDirectoryForTemplateLoading(new File("F:\\1A-java\\Java2105班\\第四阶段\\锋迷商城\\fengmi-mall\\fengmi-html\\src\\main\\resources\\freemarker"));
        configuration.setDefaultEncoding("utf-8");
        Template template = configuration.getTemplate("demo.ftl");

        List<Student> students = new ArrayList<Student>(){{
            add(new Student("迪迦",200000));
            add(new Student("麦克斯",8000000));
        }};

        Map data = new HashMap(){{
            put("username","迪迦");
            put("students",students);
        }};
        FileWriter fileWriter = new FileWriter("F:\\1A-java\\Java2105班\\第四阶段\\锋迷商城\\fengmi-mall前端\\demo.html");
        template.process(data,fileWriter);
        fileWriter.close();
    }
}
